package com.hitqz.robot.biz.flow.component.agv;

import cn.hutool.json.JSONObject;
import com.hitqz.robot.api.common.dto.robot.RobotGoTargetPosDto;
import com.hitqz.robot.api.common.entity.RobotMapPos;
import com.hitqz.robot.biz.flow.domain.constant.FlowConstant;
import com.hitqz.robot.biz.service.BusinessService;
import com.hitqz.robot.biz.service.RobotMapPosService;
import com.hitqz.robot.biz.service.RobotService;
import com.hitqz.robot.driver.parent.RobotDriverService;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.UUID;

/**
 * @Author: Wang Weiwei
 * @Description: TODO2
 * @DateTime: 2024/5/6 10:44
 **/
@Slf4j
@LiteflowComponent(value = "GoWaitForStandBy", name = "[轮对/轮轴]前往站点-等待区域")
@AllArgsConstructor
public class GoWaitForStandBy extends NodeComponent {
    private final BusinessService businessService;

    private final RobotDriverService robotDriverService;

    private final RobotService robotService;

    private final RobotMapPosService robotMapPosService;



    @Override
    public void process() throws Exception {
        String key = FlowConstant.NODE_CUSTOM_INFO_MAP.get(this.getNodeId()).getParamNames().get(0);
        Integer cmd = this.getCmpData(JSONObject.class).get(key, Integer.class);
        cmd = Math.max(0,cmd);
        log.info("[liteFlow]等待位置:{}",cmd);
        RobotMapPos robotMapPos = robotMapPosService.getById(cmd);
        robotDriverService.robotTaskGoTarget(
                RobotGoTargetPosDto.builder()
                        .robot(robotService.getDefaultRobot())
                        .code(robotMapPos.getCode())
                        .charge(false).posId(robotMapPos.getId().intValue())
                        .taskId(UUID.randomUUID().toString().replace("-","")).build());

    }
}